package be.idamf.mx.rpc
{
	import be.idamf.flash.events.dispatchEventOn;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	[Event(name="complete", type="flash.events.Event")]
	[Event(name="fault", type="mx.rpc.events.FaultEvent")]
	
	public class InjectionResponder extends EventDispatcher implements IResponder
	{
		[Bindable]
		public var target:Object;
		
		[Bindable]
		public var property:String;
		
		public function InjectionResponder(target:Object = null, property:String = null)
		{
			this.target = target;
			this.property = property;
		}
		
		public function result(data:Object):void
		{
			target[property] = ResultEvent(data).result;
			dispatchEventOn(this, Event.COMPLETE);
		}
		
		public function fault(info:Object):void
		{
			if (hasEventListener(FaultEvent.FAULT))
				dispatchEvent(FaultEvent(info));
		}
	}
}